<?php
	class m_fields extends spModel
	{
		var $pk = 'field_id';
		var $table = "fields"; // 数据表的名称

		function output($field_id, $value = '')
		{
			$m_fields = spClass('m_fields');
			$result = $m_fields->find(array('field_id'=>$field_id));
			
			if($result['field_type'] == 'select') {
				return $this->output_select($field_id, $value);
			}
			
		}

		function output_select($field_id, $value = '')
		{	
			$m_fields = spClass('m_fields');
			$result = $m_fields->find(array('field_id'=>$field_id));
			$settings = $result['settings'];
			$options = explode("\n", $settings);
			foreach($options as $option)
			{
				list($name, $id) = explode('|', trim($option));
				$selected = ($id == $value) ? 'selected' : '' ;
				
				$str_option .= '<option value="'.$id.'" ' .$selected. ' >' . $name . '</option>';
			}
			
			$str = '<select name="cat">';
			$str .= $str_option;
			$str .= '</select>';
			return $str;
		}

		function output_textarea($filed_id, $value = '')
		{
			$m_fields = spClass('m_fields');
			$result = $m_fields->find(array('field_id'=>$field_id));
			$str = '<textarea name="' . $result['field'] . '">' . $value;
			$str .= '<textarea>';
			return $str;
		}
	}
?>